import { _decorator, Component, Graphics, Material, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Box')
export class Box extends Component {
    ctx: Graphics
    flag: boolean = false;
    start() {
        const ctxNode = this.node.getChildByName("ctx");
        if (ctxNode) {
            ctxNode.setParent(this.node.parent)
            this.ctx = ctxNode.getComponent(Graphics);
            this.ctx.lineWidth = 3;
            this.ctx.strokeColor.fromHEX("#ff0000");
        }
    }
    updatePosition(x: number, y: number) {
        this.node.position = new Vec3(x, y, 0);

        if (!this.ctx) return;
        if (!this.flag) {
            this.ctx.moveTo(x, y);
            this.flag = true;
        } else {
            this.ctx.lineTo(x, y);
        }

        this.ctx.stroke();
    }

    updateRotation(angle: number) {
        this.node.angle = angle;
    }
    updateHitState(isHit: boolean) {
        if (isHit) {
            this.node.setScale(1.1, 1.1)
        }
    }
}

